const string = `* {
    box-sizing: border-box;
  }
  *::before,
  *::after {
    box-sizing: border-box;
  }
  
  .skin {
    background: #ffe600;
    position: relative;
    min-height:50vh;
  }
  
  .nose {
    border: 10px solid red;
    border-color: black transparent transparent;
    border-bottom: none;
    width: 0px;
    height: 0px;
    position: relative;
    left: 50%;
    top: 150px;
    margin-left: -10px;
    z-index: 10;
  }
  
  @keyframes wave {
    0% {
      transform: rotate(0deg);
    }
    33% {
      transform: rotate(12deg);
    }
    66% {
      transform: rotate(-12deg);
    }
    100% {
      transform: rotate(0deg);
    }
  }
  
  .nose:hover {
    transform-origin: 50% 100%;
    animation: wave 800ms linear infinite;
  }
  
  .yuan {
    position: absolute;
    width: 20px;
    height: 10px;
  
    top: -20px;
    left: -10px;
    border-radius: 20px 20px 0 0;
    background: black;
  }
  
  .eye {
    border: 1px solid #000;
    width: 64px;
    height: 64px;
    position: absolute;
    left: 50%;
    top: 100px;
    margin-left: -32px;
    background: #2e2e2e;
    border-radius: 50%;
  }
  
  .eye::before {
    content: "";
    display: block;
    border: 3px solid 000;
    width: 30px;
    height: 30px;
    background: #fff;
    border-radius: 50%;
    position: relative;
    left: 8px;
    top: 4px;
  }
  
  .eye.left {
    transform: translateX(-100px);
  }
  
  .eye.right {
    transform: translateX(100px);
  }
  
  .mouth {
    /* border: 1px solid red; */
    width: 200px;
    height: 200px;
    position: absolute;
    left: 50%;
    top: 170px;
    margin-left: -100px;
  }
  
  .mouth .up {
    position: relative;
    top: -10px;
    z-index: 1;
  }
  
  .mouth .up .lip {
    border: 4px solid black;
    height: 30px;
    width: 100px;
    background: #ffe600;
    border-top-color: transparent;
  
    position: relative;
    position: absolute;
    left: 50%;
    margin-left: -50px;
  }
  
  .mouth .up .lip.left {
    border-right-color: transparent;
    border-left-color: black;
    border-radius: 0 0 0 50px;
    transform: rotate(-20deg) translateX(-53.5px);
  }
  
  .mouth .up .lip.right {
    border-left-color: transparent;
    border-radius: 0 0 50px 0;
    transform: rotate(20deg) translateX(53.5px);
  }
  
  .mouth .up .lip::before {
    content: "";
    display: block;
  
    width: 7px;
    height: 30px;
    position: absolute;
    bottom: 0px;
  
    background: #ffe600;
  }
  
  .mouth .up .lip.left::before {
    right: -6px;
  }
  
  .mouth .up .lip.right::before {
    left: -6px;
  }
  
  .mouth .up .lip::after {
    content: "";
    display: block;
    /* border: 2px solid blue; */
    position: absolute;
    width: 100%;
    height: 5px;
    top: -7px;
    background: #ffe600;
  }
  
  /* .mouth .up .lip.left::after {
    right: -6px;
  }
  
  .mouth .up .lip.right::after {
    left: -6px;
  } */
  
  .mouth .down {
    height: 140px;
    position: absolute;
    top: 16px;
    width: 100%;
    overflow: hidden;
  }
  
  .mouth .down .yuan1 {
    border: 3px solid black;
    width: 150px;
    height: 1000px;
    position: absolute;
    bottom: 0;
    left: 50%;
    margin-left: -75px;
    border-radius: 75px/300px;
    background: #9b000a;
    overflow: hidden;
  }
  
  .mouth .down .yuan1 .yuan2 {
    width: 200px;
    height: 300px;
    background: #ff485f;
    position: absolute;
    bottom: -200px;
    left: 50%;
    margin-left: -100px;
    border-radius: 100px;
  }
  
  .face {
    position: absolute;
    left: 50%;
    border: 3px solid black;
    width: 68px;
    height: 68px;
    top: 200px;
    margin-left: -35px;
    z-index: 3;
    border-radius: 50%;
    background: #ff0000;
  }
  
  .face.left {
    transform: translateX(-170px);
  }
  
  .face.right {
    transform: translateX(170px);
  }`;

const player = {
  id: undefined,
  time: 100,
  n: 1,

  ui: {
    demo1: document.querySelector("#demo1"),
    demo2: document.querySelector("#demo2"),
  },

  events: {
    "#btnPause": "pause",
    "#btnPlay": "play",
    "#btnSlow": "slow",
    "#btnNormal": "normal",
    "#btnFast": "fast",
  },

  init: () => {
    player.ui.demo1.innerHTML = string.substr(0, player.n);
    player.ui.demo2.innerText = string.substr(0, player.n).trim();
    player.bindEvents();
    player.play();
  },

  bindEvents: () => {
    for (let key in player.events) {
      if (player.events.hasOwnProperty(key)) {
        const value = player.events[key]; // pause / play / slow
        document.querySelector(key).onclick = player[value];
      }
    }
  },

  run: () => {
    player.n += 1;
    if (player.n > string.length) {
      window.clearInterval(player.id);
      return;
    }
    player.ui.demo1.innerHTML = string.substr(0, player.n);
    player.ui.demo2.innerText = string.substr(0, player.n).trim();
    player.ui.demo2.scrollTop = player.ui.demo2.scrollHeight;
  },

  play: () => {
    player.id = setInterval(player.run, player.time);
  },

  pause: () => {
    window.clearInterval(player.id);
  },

  slow: () => {
    player.pause();
    player.time = 300;
    player.play();
  },

  normal: () => {
    player.pause();
    time = 100;
    player.play();
  },

  fast: () => {
    player.pause();
    player.time = 0;
    player.play();
  },
};

player.init();

// btnPause.onclick = () => {
//   player.pause(id);
// };

// btnPlay.onclick = player.play;

// btnSlow.onclick = player.slow;

// btnNormal.onclick = player.normal;

// btnFast.onclick = player.fast;
